//
//  CPSCTableViewCouponCell.m
//  CPSCustomer
//
//  Created by codew on 10/21/21.
//  Copyright © 2021 dgg_hzk. All rights reserved.
//

#import "CPSCTableViewCouponCell.h"
//#import "CouponResponseModel.h"

@interface CPSCTableViewCouponCell ()

@property (weak, nonatomic) IBOutlet UIImageView *imageViewBG;
@property (weak, nonatomic) IBOutlet UIImageView *imageViewLeft;
@property (weak, nonatomic) IBOutlet UIImageView *imageViewSelectStatus;
/** 满减券/折扣券 */
@property (weak, nonatomic) IBOutlet UILabel *lblMark;
/** 优惠券名称 */
@property (weak, nonatomic) IBOutlet UILabel *lblName;
/** "xxx商品"可用 */
@property (weak, nonatomic) IBOutlet UILabel *lblSummary;
/** 有效期 */
@property (weak, nonatomic) IBOutlet UILabel *lblDate;
/** 价钱 */
@property (weak, nonatomic) IBOutlet UILabel *lblPrice;
/**  */
@property (weak, nonatomic) IBOutlet UILabel *lblLeftItem1;
/**  */
@property (weak, nonatomic) IBOutlet UILabel *lblLeftItem2;
/**  */
@property (weak, nonatomic) IBOutlet UIView *viewContentSuper;


@property (nonatomic, strong) UILabel * lblMarkContent;
@end

@implementation CPSCTableViewCouponCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
    [self clearDebugColor];
    
    
    
    CAGradientLayer * layer = [self setGradualChangingColor:self.lblMark fromColor:@"#FA5741" toColor:@"#FA6D5A"];
    [self.lblMark.layer addSublayer:layer];
    [self.viewContentSuper mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(0);
    }];

    self.lblMark.layer.cornerRadius = 2;
    self.lblMark.layer.masksToBounds = YES;
    
    [self.lblMark addSubview:self.lblMarkContent];
    [self.lblMarkContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(0);
    }];
    self.lblMarkContent.text = @"满减券";
    
    
//    self.imageViewSelectStatus.image = CPSICONFONT_CONFIG(@"\U0000e65d", 16, [CPSCustomerTheme blueThemeColor]);
    
//    [_selectButton setImage: forState: UIControlStateSelected];
//    [_selectButton setImage:CPSICONFONT_CONFIG(@"\U0000e65c", 16, [CPSCustomerTheme colorCCCCCC]) forState: UIControlStateNormal];
}

- (void)clearDebugColor
{
    
    NSArray *array = @[
        self.imageViewBG,
        self.imageViewLeft,
        self.imageViewSelectStatus,
        /** 满减券/折扣券 */
        self.lblMark,
        /** 优惠券名称 */
        self.lblName,
        /** "xxx商品"可用 */
        self.lblSummary,
        /** 有效期 */
        self.lblDate,
        /** 价钱 */
        self.lblPrice,
        /**  */
        self.lblLeftItem1,
        /**  */
        self.lblLeftItem2,
        /**  */
        self.viewContentSuper
    ];
    
    for (UIView *view in array) {
        
        view.backgroundColor = [UIColor clearColor];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)updateCellWithItem:(id)item showAddMore:(BOOL)showAddMore
{
    
}

#pragma mark - SetterGetter

- (UILabel *)lblMarkContent
{
    if (!_lblMarkContent) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor whiteColor];
        lblZy.font = [UIFont systemFontOfSize:10];
        lblZy.textAlignment = NSTextAlignmentCenter;
        
        _lblMarkContent = lblZy;
    }
    
    return _lblMarkContent;
}



#pragma mark - privte


//绘制渐变色颜色的方法
- (CAGradientLayer *)setGradualChangingColor:(UIView *)view fromColor:(NSString *)fromHexColorStr toColor:(NSString *)toHexColorStr{

//    CAGradientLayer类对其绘制渐变背景颜色、填充层的形状(包括圆角)
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = view.bounds;
    
    //  创建渐变色数组，需要转换为CGColor颜色
    gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:fromHexColorStr].CGColor,(__bridge id)[UIColor colorWithHexString:toHexColorStr].CGColor];

    //  设置渐变颜色方向，左上点为(0,0), 右下点为(1,1)
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1, 1);

    //  设置颜色变化点，取值范围 0.0~1.0
    gradientLayer.locations = @[@0,@1];

    return gradientLayer;
}
@end
